requireJS(['constant', 'site', 'handlebars', 'public'], function (Constant, site, Handlebars, Public) {
    var url = {
        ftpFileList: "manager/ftpFileList.do",
        uploadFtpFile: "manager/uploadFtpFile.do"
    }
    Public.initProductSearch();
    site.send({
        url: url.ftpFileList,
        data: {},
        callback: function (data) {
            data = JSON.parse(data);
            if (data.type == '1') {
                var source = $("#file_list_tpl").html();
                var template = Handlebars.compile(source);
                var list = data.content.list
                var html = template(list)
                $('#file_list').html(html)
            }
            else {
                Constant.fn.Message("F", data.msg);
            }
        },
        callError: function (e) {

        }
    })

    var file;
    var data;

    function upLoadFile(){
        var file = $('<input type="file" name="file" id="files">')
        var form = $('<form></form>')
        file.appendTo(form);
        file.click();
        file.change(function(){
            var formData = new FormData();
            //console.log(file.files)
            formData.append("file",this.files[0]);
            site.send({
                url: url.uploadFtpFile,
                data: formData,
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                callback: function (data) {
                    //alert("上传完成!");
                },
            })
        })
    }

    $("#upload").on('click',function(){
        upLoadFile();
    })

    /*function getFile() {
        //js写法
        /!*var file=document.getElementById('fileId').files[0];//获取文件流
        var fileName =  file.name;//获取文件名*!/
        //jq写法
        /!*file = $('#file')[0].files[0];
        var formFile = new FormData();
        formFile.append("action", "UploadVMKImagePath");
        formFile.append("file", file); //加入文件对象

        data = formFile;*!/
        data = $('#file')[0].files[0];
    }

    $("#file").on('change', function (e) {
        getFile();
        console.log(data);
        /!*site.send({
            url:url.uploadFtpFile,
            data:{
                file:file
            },
            callback:function(data){
                data = JSON.parse(data);
            }
        })*!/
        $.ajax({
            url: localStorage.getItem('host') + url.uploadFtpFile,
            data: {
                file: data
            },
            type: "POST",
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (result) {
                alert("上传完成!");
            },
        })
    })*/


})